<?php
// | 初始化
// +----------------------------------------------------------------------
// | Author: carl <469714167@qq.com>
// +----------------------------------------------------------------------
// | Datetime: 2017-8-28 9:40:12
// +----------------------------------------------------------------------

namespace app\qianyu\controller;

use org\MonModel;
use think\Controller;
use think\Db;
use org\Wechat;

class Init extends Controller
{
    protected $userId;
    // protected $type;
    // protected $info;

    protected function _initialize()
    {
        if (request()->isOptions()){
            echo ''; exit();
        }
        header('Access-Control-Allow-Origin: *');
        header('Access-Control-Allow-Credentials: true');
        header('Access-Control-Allow-Methods: GET, POST, PUT, DELETE, OPTIONS');
        $param = input('post.');
        if(isset($param['userId'])){
          $this->userId = $param['userId']; 
        }
        $this->wechat = new Wechat( config('wechat_conf') );
        // $weObj = new Wechat( config('wechat_conf') );
        // dump($weObj);
        // exit;
        
        // $this->type = $param['user_type'];
        // if($this->type == 1){
        //     if (isset($param['id'])) {
        //         $this->id = $param['id'];
        //         if (empty($this->id)) {
        //             returnApi(true,'请登录',['row'=> []],200);
        //         }
        //         $this->info = Db::table('slzd_driver')->field('username,password,salt,nickname,identify,updated_at,created_at,authStatus,evaluationScore,headImg,gender,mobile,expressAuth,alias,alias_old,lat,lng,carpoolTimes,totalKm,discharge,myInviteCode,expressAuthStatus,cid,balance')->where('driverId', $this->id)->find();
        //         // echo Db::table('slzd_driver')->getLastSql();
        //         // exit;
        //         if (empty($this->info)) {
        //             returnApi(false, '司机不存在,请注册');
        //         }
        //         if (!isset($param['ApiToken'])) {
        //             returnApi(false, 'token不存在', [], 250);
        //         }
        //         if (!is_array($param['ApiToken'])) {
        //             $param['ApiToken'] = json_decode($param['ApiToken'], true);
        //         }
        //         if (!isset($param['ApiToken']['AuthKey'])) {
        //             returnApi(false, 'key不存在', [], 250);
        //         }
        //         if ($param['ApiToken']['AuthKey'] != $this->info['identify']) {
        //             returnApi(false, '验证错误请重新登录', [], 250);
        //         }
        //     }
        // } else {
        //     if (isset($param['id'])) {
        //         $this->id = $param['id'];
        //         $this->info = Db::table('slzd_user')->where('id', $this->id)->find();
//                if (empty($this->info)) {
//                    returnApi(false, '用户不存在,请注册');
//                }
//                if (!isset($param['ApiToken'])) {
//                    returnApi(false, 'token不存在', [], 250);
//                }
//                if (!is_array($param['ApiToken'])) {
//                    $param['ApiToken'] = json_decode($param['ApiToken'], true);
//                }
//                if (!isset($param['ApiToken']['AuthKey'])) {
//                    returnApi(false, 'key不存在', [], 250);
//                }
//                if ($param['ApiToken']['AuthKey'] != $this->info['identify']) {
//                    returnApi(false, '验证错误请重新登录', [], 250);
//                }
        //     }
        // }
    }

    public function Miss(){
    }

    public function saveLocation()
    {
        nearDriver('121.4879','31.24916');
    }
}